home *** CD-ROM | disk | FTP | other *** search
- package SCF;
-
- require Exporter;
- @ISA = qw(Exporter);
- @EXPORT = qw(Read Sections Keys Lookup);
-
- use strict;
-
- sub Read {
- local @ARGV = @_;
- defined @ARGV or return undef;
- my %DATA;
- my $section = '';
- while (<>) {
- chop;
- next if !length;
- next if /^;/;
- if (/^\[([-\w. ]+)\]$/) {
- $section = $1;
- } elsif (/^(\w+)\s*=\s*(.*)/) {
- $DATA{$section}{$1} = $2;
- }
- }
- return \%DATA;
- }
-
- sub Sections {
- my ($dataref) = @_;
- return keys %$dataref;
- }
-
- sub Keys {
- my ($dataref, $section) = @_;
- return keys %{$dataref->{$section}};
- }
-
- sub Lookup {
- my ($dataref, $section, $key) = @_;
- return $dataref->{$section}{$key};
- }
-
- sub Collect {
- my ($dataref, $key) = @_;
- return map { $_, $dataref->{$_}{$key} }
- grep { defined $dataref->{$_}{$key} } Sections($dataref);
- }
-